#include<iostream>
#include<algorithm>

using namespace std;

#define int long long
int n;
const int N = 1e5 + 10;
int a[N];
signed main()
{
    cin >> n;
    for(int i = 1;i <= n;i ++) cin >> a[i];

    sort(a + 1 , a + 1 + n);
    int ret = 0;
    for(int i = 1;i <= n;i ++)
    {
        ret += abs(a[i] - a[n / 2]);
    }
    cout << ret << endl;
    return 0;
}